package com.one.controller;

import com.one.annotation.RequestPermission;
import com.one.annotation.RequestUser;
import com.one.bean.Orders;
import com.one.service.QueryOrderService;
import com.one.util.RequestReturn;
import com.one.util.RequestReturnFactory;
import com.one.vo.OrderVo;
import com.one.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author ShiWen
 * @date 2022/1/17 16:41
 * @Version 1.0
 * @Description TODO 查询订单服务
 */
@RestController
@Slf4j
public class QueryOrderController {
    @Autowired
    private QueryOrderService queryOrderService;
    /**
     *  查询全部订单
     */
    @RequestPermission
    @GetMapping("/queryOrder")
    public RequestReturn<List<Orders>> queryAllOrder(@RequestUser UserVo userVo, @RequestHeader String token){
        List<Orders> orders = queryOrderService.queryAllOrder(userVo.getUserId());
        log.info("用户信息:{},token:{}",userVo,token);
        return RequestReturnFactory.success(orders);
    }
    /**
     * @description 根据订单状态查询订单
     * @author ShiWen
     * @date 2022/1/18 16:01
     */
    @GetMapping("/queryOrderByStatus")
    public RequestReturn<List<Orders>> queryOrderByStatus(@RequestUser UserVo userVo, Integer status){
        log.info("用户信息:{},订单状态:{}",userVo,status);
        List<Orders> orders = queryOrderService.queryOrderByStatus(userVo.getUserId(), status);
        return RequestReturnFactory.success(orders);
    }
    /**
     *  查询订单详细信息
     */
    @RequestPermission
    @GetMapping("/queryOrderById")
    public RequestReturn<OrderVo> queryById(@RequestUser UserVo userVo, @RequestParam Integer orderId){
        log.info("用户信息:{},订单id:{}",userVo,orderId);
        OrderVo orderVo = queryOrderService.queryOrderById(userVo.getUserId(), orderId);
        log.info("订单信息：{}",orderVo);
        return RequestReturnFactory.success(orderVo);
    }
}
